/**
 * 
 */
package view.impl.menu.items;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;


/**
 * @author Julian
 *
 */
public class ImageMenuArrow implements IMenuArrow {

	private Image img;
	private int itemPosX;
	private int itemPosY;
	private int itemHeight;
	
	public ImageMenuArrow(Image img, int itemPosX, int itemPosY, int itemHeight) {
		this.img = img;
		this.itemPosX = itemPosX;
		this.itemPosY = itemPosY;
		this.itemHeight = itemHeight;
	}
	
	/* (non-Javadoc)
	 * @see client.view.IMenuArrow#draw()
	 */
	@Override
	public void draw(Graphics g, int windowWidth, int windowHeight) {
		
		float scaleX = (float)windowWidth / 800f;
		float scaleY = (float)windowHeight / 600f;
		
		int centeredPosY = itemPosY + itemHeight / 2;
		
		int leftPosX = (int)(itemPosX + (-5 - img.getWidth()) * scaleX);
		int rightPosX = (int)(itemPosX + (5 + img.getWidth()) * scaleX);
		int posY = centeredPosY - img.getHeight() / 2;
		
		img.draw(leftPosX, posY, img.getWidth() * scaleX, img.getHeight() * scaleY);
		
		img.getFlippedCopy(true, false).draw(rightPosX, posY, img.getHeight() * scaleX, img.getHeight() * scaleY);
	}

	@Override
	public int getWidth() {
		float scaleX = 1;
		return (int) ((img.getWidth() + 5) * 2 * scaleX);
	}
	
	@Override
	public int getHeight() {
		float scaleY = 1;
		return (int) ((img.getHeight() + 5) * 2 * scaleY);
	}

	@Override
	public void setPosition(int x, int y) {
		itemPosX = x;
		itemPosY = y;
	}
	
	@Override
	public void move(int deltaX, int deltaY) {
		itemPosX += deltaX;
		itemPosY += deltaY;
	}
}
